<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="949">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #0629aa}
span.s3 {color: #506b26}
span.s4 {color: #606060}
span.s5 {color: #0d2ea2}
span.s6 {color: #576a2e}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>BufGrainB<span class="Apple-tab-span">	</span></b></span><b><span class="Apple-tab-span">	</span>granular synthesis with sound sampled in a buffer</b> <b>and user supplied envelope</b></p>
<p class="p2"><br></p>
<p class="p1"><b><span class="Apple-converted-space"> </span>*ar(trigger, dur, sndbuf, rate, pos, envbuf, interp, mul, add)<span class="Apple-converted-space"> </span></b></p>
<p class="p2"><br></p>
<p class="p1"><b><span class="Apple-tab-span">	</span>trigger </b>- a kr or ar trigger to start a new grain. If ar, grains after the start of the synth are sample accurate.</p>
<p class="p1"><span class="Apple-tab-span">	</span>The following args are polled at grain creation time</p>
<p class="p1"><span class="Apple-tab-span">	</span><b>dur</b> - size of the grain.</p>
<p class="p1"><span class="Apple-tab-span">	</span><b>sndbuf</b> - the buffer holding an audio signal</p>
<p class="p1"><span class="Apple-tab-span">	</span><b>rate</b> - the playback rate of the sampled sound</p>
<p class="p1"><b><span class="Apple-tab-span">	</span>pos</b> - the playback position for the grain to start with (0 is beginning, 1 is end of file)</p>
<p class="p1"><span class="Apple-tab-span">	</span><b>envbuf -</b> a buffer with a stored signal to be used for the envelope of the grain</p>
<p class="p1"><b><span class="Apple-tab-span">	</span>interp </b>- the kind of interpolation for the sampled sound in the grain (1 - none, 2 - linear, 4 - cubic)</p>
<p class="p2"><span class="Apple-tab-span">	</span></p>
<p class="p1"><b>Examples:</b></p>
<p class="p3"><br></p>
<p class="p4">s.boot;</p>
<p class="p3"><br></p>
<p class="p4"><span class="s2">SynthDef</span>(<span class="s3">\buf_grain_test</span>, {<span class="s2">arg</span> gate = 1, sndbuf, amp = 1, envbuf;</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="s2">Out</span>.ar(0,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">BufGrainB</span>.ar(<span class="s2">Impulse</span>.kr(10), 0.2, sndbuf, <span class="s2">MouseX</span>.kr(0.5, 8), <span class="s2">PinkNoise</span>.kr.range(0, 1),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>envbuf, 2,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">EnvGen</span>.kr(</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="s2">Env</span>([0, 1, 0], [1, 1], <span class="s3">\sin</span>, 1),</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>gate,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>levelScale: amp,</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>doneAction: 2)</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>)</p>
<p class="p4"><span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span>)</p>
<p class="p4"><span class="Apple-tab-span">	</span>}).load(s);</p>
<p class="p3"><span class="Apple-tab-span">	</span></p>
<p class="p4">s.sendMsg(<span class="s3">\b_allocRead</span>, x = s.bufferAllocator.alloc(1), <span class="s4">"sounds/a11wlk01-44_1.aiff"</span>);</p>
<p class="p4">z = <span class="s5">Env</span>([0, 1, 0], [1, 1], [10, -10]).asSignal(1024);</p>
<p class="p4">s.sendMsg(<span class="s6">\b_alloc</span>, b = s.bufferAllocator.alloc(1), 1024, 1, [<span class="s6">\b_setn</span>, b, 0, 1024] ++ z)</p>
<p class="p4">s.sendMsg(<span class="s3">\s_new</span>, <span class="s3">\buf_grain_test</span>, a=s.nextNodeID, 0, 1, <span class="s3">\amp</span>, 0.2, <span class="s3">\sndbuf</span>, x, \envbuf, b);</p>
<p class="p4">s.sendMsg(<span class="s3">\n_set</span>, a, <span class="s3">\gate</span>, 0);</p>
<p class="p4">s.sendMsg(<span class="s6">\b_free</span>, b);</p>
<p class="p4">s.sendMsg(<span class="s6">\b_free</span>, x);</p>
<p class="p3"><br></p>
</body>
</html>
